package com.shop.loan.handler;

import org.springframework.stereotype.Component;
import xyz.erupt.annotation.expr.ExprBool;
import xyz.erupt.core.context.MetaContext;
import xyz.erupt.jpa.dao.EruptDao;
import xyz.erupt.upms.model.EruptUser;

import javax.annotation.Resource;
import javax.persistence.Transient;

@Component
public class SuperAdminHandler implements ExprBool.ExprHandler {

    @Transient
    @Resource
    private EruptDao eruptDao;

    @Override
    public boolean handler(boolean expr, String[] params) {
        Boolean showByAdmin = false;
        if (MetaContext.getUser().getUid() != null) {
            showByAdmin = this.eruptDao.getEntityManager().find(EruptUser.class, Long.valueOf(MetaContext.getUser().getUid())).getIsAdmin();
        }
        //动态控制逻辑，如：根据当前登录用户判断是否为超管用户，则展示
        return showByAdmin;
    }
}
